package lfp.addressselector.bean;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Region;

/**
 * Created by Administrator on 2017/6/6.
 */

public class PathData {
    Path mPath;
    String mName;

    RectF mPathBouns;//Path所在的矩形范围

    public void setPath(Path mPath) {
        this.mPath = mPath;
        mPathBouns = new RectF();
        mPath.computeBounds(mPathBouns, true);
    }

    public void setName(String mName) {
        this.mName = mName;
    }

    public RectF getBouns() {
        return mPathBouns;
    }

    /**
     * 计算点是否在Path内
     *
     * @param x
     * @param y
     * @return
     */
    public boolean contains(int x, int y) {
        Region mRegion = new Region();
        mRegion.setPath(mPath, new Region((int) mPathBouns.left, (int) mPathBouns.top, (int) mPathBouns.right, (int) mPathBouns.bottom));
        return mRegion.contains(x, y);
    }


    public void onDraw(Canvas mCanvas, Paint mPaint,   boolean isSelected) {
//        mPaint.setShader(Shader.TileMode)
        //画板块
        mPaint.setColor(0xff222222);
        mPaint.setStyle(Paint.Style.FILL);
        mCanvas.drawPath(mPath, mPaint);

        //话边框
        mPaint.setStrokeWidth(2);
        mPaint.setColor(0xff225522);
        mPaint.setStyle(Paint.Style.STROKE);
//        mPaint.setShader( ) //着色器
//        mPaint.setXfermode( )//像素叠加
//        mPaint.setMaskFilter( ) 滤镜
        mCanvas.drawPath(mPath, mPaint);

    }

}
